﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace BPM.Base.WFLib.GuideForm
{

	public partial class BaseForm: Form
	{
        public BaseForm()
        {
            InitializeComponent();
        }

       public 等待提交 activity;
        public BaseForm(WaitSubmitDesigner designer)
		{
			InitializeComponent();

            activity = designer.Activity as 等待提交;
            //
            办理时限.Text = activity.办理时限.ToString();
            //
            string[] tps = activity.办理时特殊权限.Split(',');

            foreach (var tp in tps)
            {
                for (int i = 0; i <= this.办理时特殊权限.Items.Count - 1; i++)
                {
                    if (this.办理时特殊权限.Items[i].ToString() == tp)
                    {
                        this.办理时特殊权限.SetItemChecked(i, true);
                    }
                }
            }
            //
            string[] tos = activity.办理提交选项.Split(',');
            foreach (var to in tos)
            {
                this.办理提交选项.Items.Add(to);
            }
            //
            Load办理超时操作();

            //this.状态编号.Text = activity.状态编号;

            this.状态名称.Text = activity.状态名称;

		}

   

        public void setTransact()
        {
            activity.办理人员 = "";
            activity.接件部门 = "";
            activity.接件职能 = "";
            activity.分配部门 = "";
            activity.分配职能 = "";
            //-------------------------------------------------


           //办理时特殊权限
            string tp = "";
            
            foreach (var v in this.办理时特殊权限.CheckedItems)
            {
                tp = tp + v.ToString() + ",";
            }
            if (tp != "")
            {
                activity.办理时特殊权限 = tp.Remove(tp.Length - 1);

            }
            //办理时限
            int n;
            if(int.TryParse(办理时限.Text,out n))
            {
                activity.办理时限 = n;
            }
            else
            {
                办理时限.Text = activity.办理时限.ToString();
            }

            //办理提交选项
            activity.办理提交选项 = "";
            foreach (var to in this.办理提交选项.Items)
            {
                activity.办理提交选项 = activity.办理提交选项 + to + ",";
            }

             activity.办理提交选项=activity.办理提交选项.Remove(activity.办理提交选项.Length -1 );

            //办理超时操作
            if (this.办理超时操作.SelectedItem != null)
            {
                if (this.办理超时操作.SelectedItem.ToString() != "无")
                {
                    activity.办理超时操作 = this.办理超时操作.SelectedItem.ToString();
                }
            }
            //

             

              activity.状态名称=this.状态名称.Text;
        }

        private void button_additem_Click(object sender, EventArgs e)
        {
            if (this.textBox_item.Text == "")
            {
                return;
            }

            if (this.办理提交选项.Items.Cast<string>().Count(p => p == this.textBox_item.Text) != 0)
            {
                return;
            }

            this.办理提交选项.Items.Add(this.textBox_item.Text);

            Load办理超时操作();

        }

        void Load办理超时操作()
        {
            this.办理超时操作.Items.Clear();
            this.办理超时操作.Items.Add("无");
            foreach (var s in this.办理提交选项.Items)
            {
                this.办理超时操作.Items.Add(s);
            }

            for (int i = 0; i < this.办理超时操作.Items.Count; i++)
            {
                if (this.activity.办理超时操作 == this.办理超时操作.Items[i].ToString())
                {
                    this.办理超时操作.SelectedIndex = i;
                }
            }
        }
        private void button_removeitem_Click(object sender, EventArgs e)
        {
            if (this.办理提交选项.SelectedItem != null)
            {
                this.办理提交选项.Items.Remove(this.办理提交选项.SelectedItem);
            }

            Load办理超时操作();
  
        }

        
	}
}
